# build Lensfun library
SET(LENSFUN_SRC camera.cpp database.cpp lens.cpp 
                mount.cpp lensfunprv.h cpuid.cpp 
                mod-color-sse.cpp mod-color-sse2.cpp mod-color.cpp
                mod-coord-sse.cpp mod-coord.cpp mod-pc.cpp
                mod-subpix.cpp modifier.cpp auxfun.cpp
                ../../include/lensfun/lensfun.h.in)

SET_SOURCE_FILES_PROPERTIES(mod-color-sse.cpp mod-coord-sse.cpp
  PROPERTIES COMPILE_FLAGS "${VECTORIZATION_SSE_FLAGS}")
SET_SOURCE_FILES_PROPERTIES(mod-color-sse2.cpp
  PROPERTIES COMPILE_FLAGS "${VECTORIZATION_SSE2_FLAGS}")

IF(BUILD_STATIC)
  ADD_LIBRARY(lensfun STATIC ${LENSFUN_SRC})
ELSE()
  ADD_LIBRARY(lensfun SHARED ${LENSFUN_SRC})
  SET_TARGET_PROPERTIES(lensfun PROPERTIES COMPILE_FLAGS -DCONF_SYMBOL_VISIBILITY)
ENDIF()
SET_TARGET_PROPERTIES(lensfun PROPERTIES SOVERSION "${VERSION_API}" VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}")

TARGET_LINK_LIBRARIES(lensfun ${GLIB2_LIBRARIES})

INSTALL(TARGETS lensfun 
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

# pkgconfig support
# handle both absolute paths (e.g. NixOS) and relative for a relocatable package
IF(IS_ABSOLUTE "${CMAKE_INSTALL_BINDIR}")
    SET(LENSFUN_PC_BINDIR "${CMAKE_INSTALL_BINDIR}")
else()
    SET(LENSFUN_PC_BINDIR "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}")
ENDIF()
IF(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
    SET(LENSFUN_PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
    SET(LENSFUN_PC_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
ENDIF()
IF(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
    SET(LENSFUN_PC_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
else()
    SET(LENSFUN_PC_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
ENDIF()
IF(IS_ABSOLUTE "${CMAKE_INSTALL_DATADIR}")
    SET(LENSFUN_PC_DATADIR "${CMAKE_INSTALL_DATADIR}")
else()
    SET(LENSFUN_PC_DATADIR "\${prefix}/${CMAKE_INSTALL_DATADIR}")
ENDIF()
IF(IS_ABSOLUTE "${CMAKE_INSTALL_DOCDIR}")
    SET(LENSFUN_PC_DOCDIR "${CMAKE_INSTALL_DOCDIR}")
else()
    SET(LENSFUN_PC_DOCDIR "\${prefix}/${CMAKE_INSTALL_DOCDIR}")
ENDIF()
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/lensfun.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/lensfun.pc @ONLY)
INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/lensfun.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig )

